package com.lyc.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author ：Xiaochen
 * @date ：Created in 2022/10/27 18:19
 * @description：
 * @modified By：
 * @version:
 */
public class Text03 {
    public static void main(String[] args) throws Exception {
        Class<?> aClass = Class.forName("com.lyc.reflect.Dog");

//        Method fun2 = aClass.getDeclaredMethod("fun2", String.class, Integer.class);
//        System.out.println(fun2);
//
//        Method[] declaredMethods = aClass.getDeclaredMethods();
//        for (Method method : declaredMethods){
//            System.out.println(method);
//        }
//
//        Method fun11 = aClass.getMethod("fun1");
//        System.out.println(fun11);
//        Method show = aClass.getMethod("show");
//        System.out.println(show);
//
//        Method[] methods = aClass.getMethods();
//        for (Method method : methods){
//            System.out.println(method);
//        }


        Method fun7 = aClass.getDeclaredMethod("fun7");
        Object o = aClass.newInstance();
        Object invoke = fun7.invoke(0);
        System.out.println(invoke);

        Method fun2 = aClass.getDeclaredMethod("fun2", String.class, Integer.class);
        Object invoke1 = fun2.invoke(o, "小诗诗", 18);
        System.out.println(invoke1);

    }
}

class Animal{
    public void show(){
        System.out.println("父类1");
    }
    private void print(){
        System.out.println("父类2");
    }
}
class Dog extends  Animal{
    public void fun7(){
        System.out.println("方法1");
    }
    public String fun2(String name,Integer age){
        System.out.println("方法2"+name);
        return "嘤嘤嘤";
    }
}
